home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 3 / Gekikoh Dennoh Club Vol. 3 (Japan).7z / Gekikoh Dennoh Club Vol. 3 (Japan) (Track 1).bin / docs / panda / splay.c < prev    next >
C/C++ Source or Header  |  1998-02-19  |  7KB  |  392 lines

  1. /*
  2.     qv2 play
  3. */
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    <io.h>
  8. #include    <graph.h>
  9. #include    <doslib.h>
  10. #include    <iocslib.h>
  11.  
  12. char    Y_TBL[65536];
  13.  
  14.  
  15. unsigned short gbuf[160*120];
  16.  
  17.  
  18. int    main(argc,argv)
  19. int    argc;
  20. char    *argv[];
  21. {
  22.     FILE    *fp;
  23.     int    fn,tfn;
  24.     short    *addr;
  25. //    int    sx=48,sy=84;        //補正しない
  26.     int    sx=48,sy=38;        //補正する
  27.     int    len;
  28.     int    ed;
  29.     int    ssp;
  30.     int    mode=0;
  31.     int    st,wt;
  32.     
  33.     screen(1,3,1,1);
  34.     if( argc!=3 ){
  35.         printf("usage : @>splay file.qv2 wait");
  36.     }
  37.     CRTMOD(270);
  38. //    printf("計算中…\n");
  39. //    mktbl();
  40.     printf("データ読み込み中…\n");
  41.     fp=fopen(argv[1],"rb");
  42.     wt=atoi(argv[2]);
  43.     len=filelength(fileno(fp));
  44.  
  45.  
  46.     cls();
  47.     
  48.     ssp=B_SUPER(0);
  49.     cls();
  50.     ed=len/38400;
  51.     while(1){
  52.         fseek(fp,0,SEEK_SET);
  53.         for( fn=1;fn<=ed;fn++ ){
  54.             st=ONTIME();
  55.             printf("\x0d%03d ",fn);
  56. //            put(sx,sy,sx+159,sy+119,gbuf+19200*(fn-1),38400);    //160*120
  57.  
  58. /*
  59.             putQV2wf(sx,sy,gbuf+19200*(fn-1));    //160*120
  60. */
  61.             fread(gbuf,sizeof(short),160*120,fp);
  62.             switch( BITSNS(0x00) ){
  63.                 case 0x00:    //
  64.                     putQV2wn(sx,sy,gbuf);    //160*120
  65.                     printf("no");
  66.                 break;
  67.                 case 0x04:    //1
  68.                     putQV2wf(sx,sy,gbuf);    //160*120
  69.                     printf("fi");
  70.                 break;
  71. /*
  72.                 case 0x08:    //2
  73.                     putQV2wc(sx,sy,gbuf);    //160*120
  74.                     printf("c0");
  75.                 break;
  76.                 case 0x10:    //3
  77.                     putQV2wcc(sx,sy,gbuf);    //160*120
  78.                     printf("cc");
  79.                 break;
  80. */
  81.                 case 0x20:    //4
  82.                     if( fn&1 ){
  83.                         putQV2wn(sx,sy,gbuf);    //160*120
  84.                     }
  85.                     else{
  86.                         putQV2wf(sx,sy,gbuf);    //160*120
  87.                     }
  88.                     printf("nf");
  89.                 break;
  90.             }
  91.  
  92.             while( st+wt>ONTIME() ){
  93.                 if( BITSNS(0x00)==0x02 ){
  94.                     goto quick_exit;
  95.                 }
  96.             }
  97.         }
  98.     }
  99.     B_SUPER(ssp);
  100.  
  101.     
  102. quick_exit:;
  103.     fclose(fp);
  104.     KFLUSHIO(0xff);
  105.     
  106. }
  107.  
  108.  
  109.  
  110.  
  111. int    mktbl()
  112. {
  113.     int col;
  114.     int    r,g,b,gray;
  115.     
  116.     for( col=0;col<=0xffff;col++ ){
  117.         r=(col&0b0000011111000000)>>6;
  118.         g=(col&0b1111100000000000)>>11;
  119.         b=(col&0b0000000000111110)>>1;
  120. //        0.299 0.587 0.114
  121.         r*=1000;
  122.         g*=1000;
  123.         b*=1000;
  124.         gray=r*0.299+g*0.587+b*0.114;
  125.         gray/=1000;
  126.         Y_TBL[col]=(char)gray;
  127.     }
  128.  
  129. }
  130.  
  131.  
  132.  
  133.  
  134. //単純補間
  135. int    putQV2wn(px,py,addr)
  136. int    px,py;
  137. unsigned short    *addr;
  138. {
  139.     int    x,y;
  140.     unsigned short *s,*d;
  141.     
  142.     s=addr;
  143.     d=(unsigned short *)0xc00000+py*512+px;
  144.     for( y=0;y<120;y+=2 ){
  145.         //偶数ラインは2重描画
  146.         for( x=0;x<20;x++ ){
  147.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  148.         }
  149.         d+=352;        //512-160
  150.         s-=160;
  151.         for( x=0;x<20;x++ ){
  152.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  153.         }
  154.         d+=352;        //512-160
  155.  
  156.         for( x=0;x<20;x++ ){
  157.             *d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;*d++=*s++;
  158.         }
  159.         d+=352;        //512-160
  160.     }
  161. }
  162.  
  163.  
  164.  
  165.  
  166. //櫛形補間
  167. int    putQV2wf(px,py,addr)
  168. int    px,py;
  169. unsigned short    *addr;
  170. {
  171.     int    x,y;
  172.     unsigned short *s,*d;
  173.     
  174.     s=addr;
  175.     d=(unsigned short *)0xc00000+py*512+px;
  176.     for( y=0;y<120;y+=2 ){
  177.  
  178. /*
  179.     uuuu
  180.     udud
  181.     dddd
  182. */
  183.         //u
  184.         for( x=0;x<20;x++ ){
  185.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  186.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  187.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  188.             *(d+512)=*s;    *d++=*s++;    *d++=*s++;
  189.         }
  190. //        d+=352;        //(512-160)+512
  191.         d+=864;        //(512-160)+512
  192.  
  193.         //d
  194.         for( x=0;x<20;x++ ){
  195.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  196.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  197.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  198.             *d++=*s++;    *(d-512)=*s;    *d++=*s++;
  199.         }
  200.         d+=352;        //512-160
  201.  
  202.     }
  203. }
  204.  
  205.  
  206.  
  207. //色差計算
  208. int    putQV2wc(px,py,addr)
  209. int    px,py;
  210. unsigned short    *addr;
  211. {
  212.     int    x,y;
  213.     unsigned short *su,*sd,*du,*dm,*dd;
  214.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  215.  
  216.     su=addr;
  217.     sd=addr+160;
  218.     du=(unsigned short *)0xc00000+py*512+px;
  219.     dm=(unsigned short *)0xc00000+py*512+px+512;
  220.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  221.  
  222.     for( y=0;y<120;y+=2 ){
  223.  
  224.         //u意味なしか
  225.         for( x=0;x<40;x++ ){    *du++=*su++;*du++=*su++;*du++=*su++;*du++=*su++;    }
  226.  
  227.         //d
  228.         for( x=0;x<40;x++ ){    *dd++=*sd++;*dd++=*sd++;*dd++=*sd++;*dd++=*sd++;    }
  229.  
  230.         su-=160;
  231.         sd-=160;
  232.  
  233.         for( x=0;x<160;x++ ){
  234.             //レジスタがたりんぞい
  235.             uc=*su++;
  236.             dc=*sd++;
  237.             ur=(uc&0b0000011111000000)>>6;
  238.             ug=(uc&0b1111100000000000)>>11;
  239.             ub=(uc&0b0000000000111110)>>1;
  240.             dr=(dc&0b0000011111000000)>>6;
  241.             dg=(dc&0b1111100000000000)>>11;
  242.             db=(dc&0b0000000000111110)>>1;
  243.             mr=((ur+dr)>>1)<<6;
  244.             mg=((ug+dg)>>1)<<11;
  245.             mb=((ub+db)>>1)<<1;
  246.             mc=mr;
  247.             mc|=mg;
  248.             mc|=mb;
  249.             *dm++=mc;
  250.         }
  251.  
  252.         du+=1376;        //(512-160)+1024
  253.         dm+=1376;
  254.         dd+=1376;
  255.         su+=160;
  256.         sd+=160;
  257.  
  258.     }
  259.  
  260.  
  261. }
  262.  
  263.  
  264.  
  265.  
  266. //色差検査後計算orコピー
  267. int    putQV2wcc(px,py,addr)
  268. int    px,py;
  269. unsigned short    *addr;
  270. {
  271.     int    x,y;
  272.     unsigned short *su,*sd,*du,*dm,*dd;
  273.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  274.     
  275.     su=addr;
  276.     sd=addr+160;
  277.     du=(unsigned short *)0xc00000+py*512+px;
  278.     dm=(unsigned short *)0xc00000+py*512+px+512;
  279.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  280.  
  281.     for( y=0;y<120;y+=2 ){
  282.  
  283.         //u意味なしか
  284.         for( x=0;x<40;x++ ){    *du++=*su++;*du++=*su++;*du++=*su++;*du++=*su++;    }
  285.  
  286.         //d
  287.         for( x=0;x<40;x++ ){    *dd++=*sd++;*dd++=*sd++;*dd++=*sd++;*dd++=*sd++;    }
  288.  
  289.         su-=160;
  290.         sd-=160;
  291.  
  292.         for( x=0;x<160;x++ ){
  293.             //レジスタがたりんぞい
  294.             uc=*su++;
  295.             dc=*sd++;
  296.  
  297. //            printf("%d,",(max((int)Y_TBL[uc],(int)Y_TBL[dc])-min((int)Y_TBL[uc],(int)Y_TBL[dc])));
  298.  
  299.             if( (max((int)Y_TBL[uc],(int)Y_TBL[dc])-min((int)Y_TBL[uc],(int)Y_TBL[dc]))>=12 ){
  300.                 //37.5%以上の輝度変化があった場合
  301.                 ur=(uc&0b0000011111000000)>>6;
  302.                 ug=(uc&0b1111100000000000)>>11;
  303.                 ub=(uc&0b0000000000111110)>>1;
  304.                 dr=(dc&0b0000011111000000)>>6;
  305.                 dg=(dc&0b1111100000000000)>>11;
  306.                 db=(dc&0b0000000000111110)>>1;
  307.                 mr=((ur+dr)>>1)<<6;
  308.                 mg=((ug+dg)>>1)<<11;
  309.                 mb=((ub+db)>>1)<<1;
  310.                 mc=mr;
  311.                 mc|=mg;
  312.                 mc|=mb;
  313.                 *dm++=mc;
  314.             }
  315.             else{
  316.                 //変化が少なければ上の色をそのまま
  317.                 *dm++=uc;
  318.             }
  319.  
  320.         }
  321.  
  322.         du+=1376;        //(512-160)+1024
  323.         dm+=1376;
  324.         dd+=1376;
  325.         su+=160;
  326.         sd+=160;
  327.  
  328.     }
  329.  
  330.  
  331. }
  332.  
  333.  
  334.  
  335.  
  336. //色差計算for 68060
  337. int    putQV2wc060(px,py,addr)
  338. int    px,py;
  339. unsigned short    *addr;
  340. {
  341.     int    x,y;
  342.     unsigned short *su,*sd,*du,*dm,*dd;
  343.     unsigned short    uc,mc,dc,    ur,ug,ub,    dr,dg,db,    mr,mg,mb;
  344.  
  345.     su=addr;
  346.     sd=addr+160;
  347.     du=(unsigned short *)0xc00000+py*512+px;
  348.     dm=(unsigned short *)0xc00000+py*512+px+512;
  349.     dd=(unsigned short *)0xc00000+py*512+px+1024;
  350.  
  351.     for( y=0;y<120;y+=2 ){
  352.  
  353.         for( x=0;x<160;x++ ){
  354.  
  355.             uc=*su++;
  356.             dc=*sd++;
  357.  
  358.             *du++=uc;
  359.             *dd++=dc;
  360.  
  361.             uc&=0b0000011111000000;
  362.             uc>>=6;
  363.             ur=uc;                //@@以下、
  364.             ug=(uc&0b1111100000000000)>>11;
  365.             ub=(uc&0b0000000000111110)>>1;
  366.             dr=(dc&0b0000011111000000)>>6;
  367.             dg=(dc&0b1111100000000000)>>11;
  368.             db=(dc&0b0000000000111110)>>1;
  369.             mr=((ur+dr)>>1)<<6;
  370.             mg=((ug+dg)>>1)<<11;
  371.             mb=((ub+db)>>1)<<1;
  372.             mc=mr;
  373.             mc|=mg;
  374.             mc|=mb;
  375.             *dm++=mc;
  376.         }
  377.  
  378.         du+=1376;        //(512-160)+1024
  379.         dm+=1376;
  380.         dd+=1376;
  381.         su+=160;
  382.         sd+=160;
  383.  
  384.     }
  385.  
  386.  
  387. }
  388.  
  389.  
  390.  
  391.  
  392.